﻿using Public;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Check_Barcode
{
    public partial class baidusound : Form
    {
        public baidusound()
        {
            InitializeComponent();
        }
        public static string APP_ID = "16056176";
        public static string API_KEY = "3yPT6eeqdWGlhWGytc9GhdHp";
        public static string SECRET_KEY = "0QhbCQ8jGmcg6qbiPTQGG5EvK8USGCFm";

        Baidu.Aip.Speech.Tts _ttsClient = new Baidu.Aip.Speech.Tts(API_KEY, SECRET_KEY);

        private void button1_Click(object sender, EventArgs e)
        {
         
            var client = new Baidu.Aip.Speech.Tts(API_KEY, SECRET_KEY);
            client.Timeout = 60000;  // 修改超时时间
            Tts();
        }

        public void Tts()
        {
            // 可选参数
            var option = new Dictionary<string, object>()
            {
                {"spd", 4}, // 语速
                {"vol", 7}, // 音量
                {"per", 2}  // 发音人，4：情感度丫丫童声
            };
            var result = _ttsClient.Synthesis(textBox1.Text, option);

            if (result.ErrorCode == 0)  // 或 result.Success
            {
                File.WriteAllBytes("合成的语音文件本地存储地址.mp3", result.Data);
            }
            Mp3Player mp3Play = new Mp3Player()
            {
             FileName = "合成的语音文件本地存储地址.mp3",
            };
            mp3Play.play();
        }


    }
}
